'use strict'

const pg = require('pg')

let psql = new pg.Pool({
    database: 'zfy',
    user: 'zfy',
    port: 5432,
    host: '127.0.0.1',
    password: 'zhaofuyu1234',
    // 最大使用5个客户端链接
    max: 5
})

// 括号开头加分号
;(async ()=>{
    let tm = Date.now()
    // 随机数字转换成16进制并去掉前两位
    let id = `${Math.random().toString(16).substring(2)}`
    let sqltest = `INSERT INTO `
    + ` content(id,detail,title,add_time,update_time) `
    + ` VALUES($1,$2,$3,$4,$5)`
    let r = await psql.query(sqltest,[
        id, `测试内容:${Math.random()}`, 'test', tm, tm
    ])
    console.log(r)

    //关闭连接
    psql.end()
})();